package com.alibaba.citrus.cr.sales.plan.repository;

import com.alibaba.citrus.cr.common.annotation.RepositoryInvoker;
import com.alibaba.citrus.cr.common.exception.RepositoryException;
import com.alibaba.citrus.cr.common.util.CalculatePercentage;
import com.alibaba.citrus.cr.sales.plan.dto.api.request.PageQueryPlanAdjustDetailRequest;
import com.alibaba.citrus.cr.sales.plan.dto.api.request.QueryPlanAdjustDetailRequest;
import com.alibaba.citrus.cr.sales.plan.dto.api.request.QuerySalesPlanRequest;
import com.alibaba.citrus.cr.sales.plan.dto.api.request.SalesPlanAdjustDetailBatchQueryRequest;
import com.alibaba.citrus.cr.sales.plan.dto.api.request.SalesPlanAdjustDetailSubTotalRequest;
import com.alibaba.citrus.cr.sales.plan.dto.api.response.SalesPlanAdjustDetailSubTotalResponse;
import com.alibaba.citrus.cr.sales.plan.dto.api.response.SalesPlanSubTotalResponse;
import com.alibaba.citrus.cr.sales.plan.model.SalesPlanLineStatusEnum;
import com.alibaba.citrus.cr.sales.plan.model.enums.ContractDifferenceMoneyStampEnum;
import com.alibaba.citrus.cr.sales.plan.model.features.SalesPlanAdjustDetailFeatures;
import com.alibaba.citrus.cr.sales.plan.sdo.SalesPlanAdjustDetailSDO;
import com.alibaba.citrus.cr.sales.plan.sdo.SalesPlanSDO;
import com.alibaba.cz.base.tool.StringUtil;
import com.alibaba.cz.base.tool.page.PageResult;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.bcorder.model.dto.ScItemSDO;
import com.epoch.app.bcorder.model.dto.SearchScItemRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.BatchCreateSalesPlanAdjustDetailRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.BatchCreateSalesPlanAdjustDetailResponse;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.BatchDeleteAdjustDetailRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.BatchDeleteAdjustDetailResponse;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.BatchQueryDetailByIdsRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.BatchQueryDetailByIdsResponse;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.BatchUpdateAdjustDetailStatusRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.BatchUpdateAdjustDetailStatusResponse;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.LoadSalesPlanAdjustDetailListRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.LoadSalesPlanAdjustDetailRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.QueryByAdjustDetailCompletePercentRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.QueryByAdjustDetailCompletePercentResponse;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.SubTotalSalesPlanAdjustDetailRequest;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.SubTotalSalesPlanAdjustDetailResponse;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.dto.UpdateSalesPlanAdjustDetailResponse;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.model.SalesPlanAdjustDetail;
import com.epoch.app.bcorder.sales_plan.salesplanadjustdetail.service.SalesPlanAdjustDetailService;
import com.epoch.app.bcorder.service.BaseDataService;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import net.sf.json.JSONObject;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author yuhailin
 * @description:
 * @date 2021-10-25 21:08
 */
@Component
public class SalesPlanAdjustDetailRepositoryImpl implements SalesPlanAdjustDetailRepository {

    @Resource
    private SalesPlanAdjustDetailService salesPlanAdjustDetailService;

    @Resource
    private BaseDataService baseDataService;

    @Override
    @RepositoryInvoker(printLog = true)
    public PageResult<List<SalesPlanAdjustDetailSDO>> pageQuerySalesPlanAdjustDetailList(PageQueryPlanAdjustDetailRequest pageQueryPlanAdjustDetailRequest) {
        LoadSalesPlanAdjustDetailListRequest salesPlanAdjustDetailLoadListRequest = loadSalesPlanAdjustDetailListRequestConvert(pageQueryPlanAdjustDetailRequest);
        Result<List<SalesPlanAdjustDetail>> listResult = salesPlanAdjustDetailService.loadSalesPlanAdjustDetailList(salesPlanAdjustDetailLoadListRequest);
        if (null == listResult || CollectionUtils.isEmpty(listResult.getResult())) {
            return PageResult.of(Lists.newArrayList(), 0);
        }
        List<SalesPlanAdjustDetailSDO> collect = listResult.getResult().stream().map(salesPlanAdjustDetail -> {
            SalesPlanAdjustDetailSDO salesPlanAdjustDetailSDO = SalesPlanAdjustDetailSDO.builder().build();
            BeanUtils.copyProperties(salesPlanAdjustDetail, salesPlanAdjustDetailSDO);
            if (StringUtil.isNotEmpty(salesPlanAdjustDetail.getFeatures())) {
                SalesPlanAdjustDetailFeatures salesPlanAdjustDetailFeatures = (SalesPlanAdjustDetailFeatures) JSONObject.toBean(JSONObject.fromObject(salesPlanAdjustDetail.getFeatures()), SalesPlanAdjustDetailFeatures.class);
                salesPlanAdjustDetailSDO.setSalesPlanAdjustDetailFeatures(salesPlanAdjustDetailFeatures);
            }
            return salesPlanAdjustDetailSDO;
        }).collect(Collectors.toList());
        return PageResult.of(collect, listResult.getTotal());
    }

    private LoadSalesPlanAdjustDetailListRequest loadSalesPlanAdjustDetailListRequestConvert(PageQueryPlanAdjustDetailRequest pageQueryPlanAdjustDetailRequest){
        LoadSalesPlanAdjustDetailListRequest salesPlanAdjustDetailLoadListRequest = new LoadSalesPlanAdjustDetailListRequest();
        BeanUtils.copyProperties(pageQueryPlanAdjustDetailRequest, salesPlanAdjustDetailLoadListRequest);
        if (StringUtil.isNotEmpty(pageQueryPlanAdjustDetailRequest.getAdjustId())) {
            salesPlanAdjustDetailLoadListRequest.setAdjustId(Long.valueOf(pageQueryPlanAdjustDetailRequest.getAdjustId()));
        }
        if (ContractDifferenceMoneyStampEnum.SATISFY.getStamp().equals(pageQueryPlanAdjustDetailRequest.getContractDifferenceMoneyStamp())) {
            salesPlanAdjustDetailLoadListRequest.setGtSatisfy(0);
        } else if (ContractDifferenceMoneyStampEnum.DISSATISFY.getStamp().equals(pageQueryPlanAdjustDetailRequest.getContractDifferenceMoneyStamp())) {
            salesPlanAdjustDetailLoadListRequest.setLtSatisfy(0);
        }

        List<String> scItemIdList = new ArrayList<>();
        if (StringUtils.isNotBlank(pageQueryPlanAdjustDetailRequest.getScItemId())) {
            scItemIdList.add(pageQueryPlanAdjustDetailRequest.getScItemId());
        }
        if (StringUtils.isNotBlank(pageQueryPlanAdjustDetailRequest.getScItemCode())) {
            SearchScItemRequest request = new SearchScItemRequest();
            Map<String,Object> searchReqDTO = new HashMap<>();
            searchReqDTO.put("outerIdList", Lists.newArrayList(pageQueryPlanAdjustDetailRequest.getScItemCode()));
            request.setSearchReqDTO(searchReqDTO);
            Result<List<ScItemSDO>> result = baseDataService.searchScItem(request);
            if (Objects.isNull(result) || CollectionUtils.isEmpty(result.getResult())) {
                scItemIdList.add("-1");
            }else{
                scItemIdList.addAll(result.getResult().stream().map(x->x.getScItemId()).collect(Collectors.toList()));
            }
        }
        if(CollectionUtils.isNotEmpty(scItemIdList)){
            salesPlanAdjustDetailLoadListRequest.setScItemIds(scItemIdList);
        }
        return salesPlanAdjustDetailLoadListRequest;
    }

    @Override
    @RepositoryInvoker(printLog = true)
    public String batchCreateSalesPlanAdjustDetail(List<SalesPlanAdjustDetailSDO> salesPlanAdjustDetailSDOList) {
        salesPlanAdjustDetailSDOList.stream().forEach(sdo -> sdo.setId(null));
        BatchCreateSalesPlanAdjustDetailRequest batchCreateSalesPlanAdjustDetailRequest = BatchCreateSalesPlanAdjustDetailRequest.builder().salesPlanAdjustDetailSDOList(salesPlanAdjustDetailSDOList).build();
        BatchCreateSalesPlanAdjustDetailResponse batchCreateSalesPlanAdjustDetailResponse = salesPlanAdjustDetailService.batchCreateSalesPlanAdjustDetail(batchCreateSalesPlanAdjustDetailRequest);
        return batchCreateSalesPlanAdjustDetailResponse.getSuccess();
    }

    @Override
    @RepositoryInvoker(printLog = true)
    public SalesPlanSubTotalResponse subTotalSalesPlanAdjustDetail(SalesPlanAdjustDetailSubTotalRequest salesPlanAdjustDetailSubTotalRequest) {
        PageQueryPlanAdjustDetailRequest pageQueryPlanAdjustDetailRequest = new PageQueryPlanAdjustDetailRequest();
        BeanUtils.copyProperties(salesPlanAdjustDetailSubTotalRequest,pageQueryPlanAdjustDetailRequest);
        LoadSalesPlanAdjustDetailListRequest tempRequest = loadSalesPlanAdjustDetailListRequestConvert(pageQueryPlanAdjustDetailRequest);
        SubTotalSalesPlanAdjustDetailRequest subTotalSalesPlanAdjustDetailRequest = SubTotalSalesPlanAdjustDetailRequest.builder().build();
        BeanUtils.copyProperties(tempRequest,subTotalSalesPlanAdjustDetailRequest);

        SubTotalSalesPlanAdjustDetailResponse subTotalStatResponse = salesPlanAdjustDetailService.subTotalSalesPlanAdjustDetail(subTotalSalesPlanAdjustDetailRequest);

        SalesPlanSubTotalResponse salesPlanSubTotalResponse = SalesPlanSubTotalResponse.builder().build();
        BeanUtils.copyProperties(subTotalStatResponse, salesPlanSubTotalResponse);
        salesPlanSubTotalResponse.setAdjustId(salesPlanAdjustDetailSubTotalRequest.getAdjustId()!=null?Long.valueOf(salesPlanAdjustDetailSubTotalRequest.getAdjustId()):null);

//        SalesPlanAdjustDetailSubTotalResponse salesPlanAdjustDetailSubTotalResponse = SalesPlanAdjustDetailSubTotalResponse.builder().build();
//        BeanUtils.copyProperties(subTotalSalesPlanAdjustDetailResponse, salesPlanAdjustDetailSubTotalResponse);
//        Integer monthFirstAdjustReturnCount = subTotalSalesPlanAdjustDetailResponse.getMonthFirstAdjustReturnCount() != null ? subTotalSalesPlanAdjustDetailResponse.getMonthFirstAdjustReturnCount() : 0;
//        Integer monthMiddleAdjustReturnCount = subTotalSalesPlanAdjustDetailResponse.getMonthMiddleAdjustReturnCount() != null ? subTotalSalesPlanAdjustDetailResponse.getMonthMiddleAdjustReturnCount() : 0;
//        Integer monthLastAdjustReturnCount = subTotalSalesPlanAdjustDetailResponse.getMonthLastAdjustReturnCount() != null ? subTotalSalesPlanAdjustDetailResponse.getMonthLastAdjustReturnCount() : 0;
//        salesPlanAdjustDetailSubTotalResponse.setAdjustReturnCount(monthFirstAdjustReturnCount + monthMiddleAdjustReturnCount + monthLastAdjustReturnCount);
//        if (subTotalSalesPlanAdjustDetailResponse.getCostInsuranceFreight() != null) {
//            //TODO 酥卿 理论上只要总金额不超过2kw，这里不会有溢出问题；但是类似问题还是需要关注一下；
//            salesPlanAdjustDetailSubTotalResponse.setBeforeAdjustReturnMoney((long) (subTotalSalesPlanAdjustDetailResponse.getMonthFirstAdjustReturnMoney() + subTotalSalesPlanAdjustDetailResponse.getMonthMiddleAdjustReturnMoney() + subTotalSalesPlanAdjustDetailResponse.getMonthLastAdjustReturnMoney()));
//            if (load.getEstimateDiscount() != null) {
//                BigDecimal multiply = load.getEstimateDiscount().multiply(new BigDecimal("0.01").setScale(2, RoundingMode.HALF_UP));
//                BigDecimal subtract = new BigDecimal(1).subtract(multiply);
//                salesPlanAdjustDetailSubTotalResponse.setAdjustReturnMoney(new BigDecimal(salesPlanAdjustDetailSubTotalResponse.getBeforeAdjustReturnMoney()).multiply(subtract).longValue());
//            }
//        }
//        //折前满足率(折后任务金额/折后合同金额)
//        long taskMoney = Objects.isNull(salesPlanAdjustDetailSubTotalResponse.getTaskMoney()) ? 0 : salesPlanAdjustDetailSubTotalResponse.getTaskMoney();
//        long monthContractMoney = Objects.isNull(salesPlanAdjustDetailSubTotalResponse.getMonthContractMoney()) ? 0 : salesPlanAdjustDetailSubTotalResponse.getMonthContractMoney();
//        BigDecimal beforeSatisfyRate = CalculatePercentage.retainTwoBigDecimalPercentage2(new BigDecimal(taskMoney), new BigDecimal(monthContractMoney));
//        salesPlanAdjustDetailSubTotalResponse.setBeforeSatisfyRate(beforeSatisfyRate);
//        //折后满足率（折后任务金额+折后任务调整回复金额）/折后合同金额
//        long adjustReturnMoney = Objects.isNull(salesPlanAdjustDetailSubTotalResponse.getAdjustReturnMoney()) ? 0 : salesPlanAdjustDetailSubTotalResponse.getAdjustReturnMoney();
//        long adjustTaskReturnMoney = taskMoney + adjustReturnMoney;
//        BigDecimal satisfyRate = CalculatePercentage.retainTwoBigDecimalPercentage2(new BigDecimal(adjustTaskReturnMoney), new BigDecimal(monthContractMoney));
//        salesPlanAdjustDetailSubTotalResponse.setSatisfyRate(satisfyRate);
        return salesPlanSubTotalResponse;
    }

    @Override
    @RepositoryInvoker(printLog = true)
    public BigDecimal queryCompletePercent(SalesPlanAdjustDetailSubTotalRequest salesPlanAdjustDetailSubTotalRequest) {
        QueryByAdjustDetailCompletePercentRequest queryByAdjustDetailCompletePercentRequest = new QueryByAdjustDetailCompletePercentRequest();
        BeanUtils.copyProperties(salesPlanAdjustDetailSubTotalRequest, queryByAdjustDetailCompletePercentRequest);
        //全部
        QueryByAdjustDetailCompletePercentResponse allPercentResponse = salesPlanAdjustDetailService.queryByAdjustDetailCompletePercent(queryByAdjustDetailCompletePercentRequest);
        if (allPercentResponse != null && allPercentResponse.getCount() != 0) {
            //未完成
            queryByAdjustDetailCompletePercentRequest.setStatus(SalesPlanLineStatusEnum.DRAFT.getStatus());
            QueryByAdjustDetailCompletePercentResponse toBeLockedPercentResponse = salesPlanAdjustDetailService.queryByAdjustDetailCompletePercent(queryByAdjustDetailCompletePercentRequest);
            Long toBeLockedCount = toBeLockedPercentResponse.getCount() != null ? toBeLockedPercentResponse.getCount() : 0L;
            return CalculatePercentage.retainTwo(allPercentResponse.getCount() - toBeLockedCount, allPercentResponse.getCount());
        }
        return new BigDecimal("0");
    }

    @Override
    @RepositoryInvoker(printLog = true)
    public Integer edit(SalesPlanAdjustDetailSDO salesPlanAdjustDetailSDO) {
        SalesPlanAdjustDetail salesPlanAdjustDetail = salesPlanAdjustDetailConvert(salesPlanAdjustDetailSDO);
        UpdateSalesPlanAdjustDetailResponse updateSalesPlanAdjustDetailResponse = salesPlanAdjustDetailService.updateSalesPlanAdjustDetail(salesPlanAdjustDetail);
        return updateSalesPlanAdjustDetailResponse.getCount();
    }

    @Override
    @RepositoryInvoker(printLog = true)
    public SalesPlanAdjustDetailSDO querySalesPlanAdjustDetailList(
        QueryPlanAdjustDetailRequest queryPlanAdjustDetailRequest) {
        LoadSalesPlanAdjustDetailRequest loadSalesPlanAdjustDetailRequest = new LoadSalesPlanAdjustDetailRequest();
        loadSalesPlanAdjustDetailRequest.setId(Long.valueOf(queryPlanAdjustDetailRequest.getId()));
        SalesPlanAdjustDetail salesPlanAdjustDetail = salesPlanAdjustDetailService.loadSalesPlanAdjustDetail(loadSalesPlanAdjustDetailRequest);
        SalesPlanAdjustDetailSDO salesPlanAdjustDetailSDO = SalesPlanAdjustDetailSDO.builder().build();
        BeanUtils.copyProperties(salesPlanAdjustDetail, salesPlanAdjustDetailSDO);
        return salesPlanAdjustDetailSDO;
    }

    @Override
    @RepositoryInvoker(printLog = true)
    public List<SalesPlanAdjustDetailSDO> batchQueryDetail(
        SalesPlanAdjustDetailBatchQueryRequest salesPlanAdjustDetailBatchQueryRequest) {
        BatchQueryDetailByIdsRequest batchQueryDetailByIdsRequest = new BatchQueryDetailByIdsRequest();
        BeanUtils.copyProperties(salesPlanAdjustDetailBatchQueryRequest, batchQueryDetailByIdsRequest);
        BatchQueryDetailByIdsResponse batchQueryDetailByIdsResponse = salesPlanAdjustDetailService.batchQueryDetailByIds(batchQueryDetailByIdsRequest);
        List<SalesPlanAdjustDetailSDO> salesPlanLineSDOS = batchQueryDetailByIdsResponse.getResult().stream().map(salesPlanAdjustDetail -> {
            SalesPlanAdjustDetailSDO salesPlanAdjustDetailSDO = SalesPlanAdjustDetailSDO.builder().build();
            BeanUtils.copyProperties(salesPlanAdjustDetail, salesPlanAdjustDetailSDO);
            if (StringUtil.isNotEmpty(salesPlanAdjustDetail.getFeatures())) {
                SalesPlanAdjustDetailFeatures salesPlanAdjustDetailFeatures = (SalesPlanAdjustDetailFeatures) JSONObject.toBean(JSONObject.fromObject(salesPlanAdjustDetail.getFeatures()), SalesPlanAdjustDetailFeatures.class);
                salesPlanAdjustDetailSDO.setSalesPlanAdjustDetailFeatures(salesPlanAdjustDetailFeatures);
            }
            return salesPlanAdjustDetailSDO;
        }).collect(Collectors.toList());
        return salesPlanLineSDOS;
    }

    @Override
    @RepositoryInvoker(printLog = true)
    public Integer batchUpdateAdjustDetailStatus(List<SalesPlanAdjustDetailSDO> salesPlanAdjustDetailSDOList) {
        List<Long> ids = salesPlanAdjustDetailSDOList.stream().map(SalesPlanAdjustDetailSDO::getId).collect(Collectors.toList());
        BatchUpdateAdjustDetailStatusRequest batchUpdateAdjustDetailStatusRequest = BatchUpdateAdjustDetailStatusRequest.builder()
                .ids(ids)
                .status(SalesPlanLineStatusEnum.DELETE.getStatus()).build();
        BatchUpdateAdjustDetailStatusResponse batchUpdateAdjustDetailStatusResponse = salesPlanAdjustDetailService.batchUpdateAdjustDetailStatus(batchUpdateAdjustDetailStatusRequest);
        return batchUpdateAdjustDetailStatusResponse.getCount();
    }

    @Override
    public Integer deleteAdjustDetail(String planId, List<String> scItemIdList, List<String> customerAddressIdList) {
        BatchDeleteAdjustDetailRequest batchDeleteAdjustDetailRequest = BatchDeleteAdjustDetailRequest.builder()
                .planId(planId)
                .scItemIdList(scItemIdList)
                .customerAddressIdList(customerAddressIdList).build();
        BatchDeleteAdjustDetailResponse batchDeleteAdjustDetailResponse = salesPlanAdjustDetailService.batchDeleteAdjustDetail(batchDeleteAdjustDetailRequest);
        return batchDeleteAdjustDetailResponse.getCount();
    }

    private SalesPlanAdjustDetail salesPlanAdjustDetailConvert(SalesPlanAdjustDetailSDO salesPlanAdjustDetailSDO) {
        SalesPlanAdjustDetail salesPlanAdjustDetail = new SalesPlanAdjustDetail();
        BeanUtils.copyProperties(salesPlanAdjustDetailSDO, salesPlanAdjustDetail);
        if (salesPlanAdjustDetailSDO.getId() != null) {
            salesPlanAdjustDetail.setId(salesPlanAdjustDetailSDO.getId());
        }
        //调整总量
        if (salesPlanAdjustDetailSDO.getAdjustCount() != null) {
            salesPlanAdjustDetail.setAdjustCount(salesPlanAdjustDetailSDO.getAdjustCount());
        }
        //折后调整金额
        if (salesPlanAdjustDetailSDO.getAdjustMoney() != null) {
            salesPlanAdjustDetail.setAdjustMoney(salesPlanAdjustDetailSDO.getAdjustMoney());
        }
        //折前调整金额
        if (salesPlanAdjustDetailSDO.getBeforeAdjustMoney() != null) {
            salesPlanAdjustDetail.setBeforeAdjustMoney(salesPlanAdjustDetailSDO.getBeforeAdjustMoney());
        }
        //上旬调整量
        if (salesPlanAdjustDetailSDO.getMonthFirstAdjustCount() != null) {
            salesPlanAdjustDetail.setMonthFirstAdjustCount(salesPlanAdjustDetailSDO.getMonthFirstAdjustCount());
        }
        //中旬调整量
        if (salesPlanAdjustDetailSDO.getMonthMiddleAdjustTotalCount() != null) {
            salesPlanAdjustDetail.setMonthMiddleAdjustCount(salesPlanAdjustDetailSDO.getMonthMiddleAdjustCount());
        }
        //下旬调整量
        if (salesPlanAdjustDetailSDO.getMonthLastAdjustTotalCount() != null) {
            salesPlanAdjustDetail.setMonthLastAdjustCount(salesPlanAdjustDetailSDO.getMonthLastAdjustCount());
        }
        //合同差量
        if (salesPlanAdjustDetailSDO.getContractDifferenceCount() != null) {
            salesPlanAdjustDetail.setContractDifferenceCount(salesPlanAdjustDetailSDO.getContractDifferenceCount());
        }
        //折后满足度
        if (salesPlanAdjustDetailSDO.getContractSatisfaction() != null) {
            salesPlanAdjustDetail.setContractSatisfaction(salesPlanAdjustDetailSDO.getContractSatisfaction());
        }
        //折前满足度
        if (salesPlanAdjustDetailSDO.getBeforeContractSatisfaction() != null) {
            salesPlanAdjustDetail.setBeforeContractSatisfaction(salesPlanAdjustDetailSDO.getBeforeContractSatisfaction());
        }
        //上旬调整回复量
        if (salesPlanAdjustDetailSDO.getMonthFirstAdjustReturnCount() != null) {
            salesPlanAdjustDetail.setMonthFirstAdjustReturnCount(salesPlanAdjustDetailSDO.getMonthFirstAdjustReturnCount());
        }
        //中旬调整回复量
        if (salesPlanAdjustDetailSDO.getMonthMiddleAdjustReturnCount() != null) {
            salesPlanAdjustDetail.setMonthMiddleAdjustReturnCount(salesPlanAdjustDetailSDO.getMonthMiddleAdjustReturnCount());
        }
        //下旬调整回复量
        if (salesPlanAdjustDetailSDO.getMonthLastAdjustReturnCount() != null) {
            salesPlanAdjustDetail.setMonthLastAdjustReturnCount(salesPlanAdjustDetailSDO.getMonthLastAdjustReturnCount());
        }
        return salesPlanAdjustDetail;
    }
}
